Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Friend Class frmMain
	Inherits System.Windows.Forms.Form
	
	'
	'  TO DO LIST:
	'
	'  -Fix "switch to" thing.
	'  *Trim quoted computer names on txt import
	'  *Fix bug with "clear" inserting dups (maybe fixed now...)
	'  -Fix issue with DHCPImport.txt on VPCDC02
	'
	'
	
	Const DIRECT_RULE_PROP_COUNT As Integer = 3
	Const QUERY_RULE_PROP_COUNT As Integer = 4
	Public WithEvents mobjConn As SiteServerConnection
	Public mobjCollCache As SMSCollectionList
	Public mobjComputerResIDs As Scripting.Dictionary
	Private Const mstrLoading As String = "<Loading child collections...>"
	
	
	Private Sub CacheCollNames()
		If mobjConn.Connected = False Then
			Exit Sub
		End If
		Dim flgSuccess As Boolean
		mobjCollCache = New SMSCollectionList
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
		flgSuccess = mobjCollCache.CacheCollections(mobjConn.SMSServices)
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		If flgSuccess Then
			Debug.Print("Successfully cached collection names...")
		Else
			Debug.Print("Failed caching collection names...")
		End If
	End Sub
	
	Private Function VerifiedCount() As Integer
		If lstComputersToAdd.Font.Bold = True Then
			VerifiedCount = lstComputersToAdd.Items.Count
		Else
			VerifiedCount = 0
		End If
	End Function
	
	Private Function CollectionFirstCheckedName() As String
		Dim lngIndex As Integer
		CollectionFirstCheckedName = "" 'default
		For lngIndex = 1 To TreeView1.Nodes.Count
			'UPGRADE_WARNING: Lower bound of collection TreeView1.Nodes has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			If TreeView1.Nodes.Item(lngIndex).Checked = True Then
				'UPGRADE_WARNING: Lower bound of collection TreeView1.Nodes has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				CollectionFirstCheckedName = TreeView1.Nodes.Item(lngIndex).Text
				Exit Function 'Just need the first one...
			End If
		Next 
	End Function
	
	
	
	Private Sub cmdAdd_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAdd.Click
		
		Dim response As MsgBoxResult
		
		If VerifiedCount = 0 Then
			Exit Sub
		End If
		
		If CollectionCheckedCount = 1 Then
			If VerifiedCount = 1 Then
				response = MsgBox("Are you sure you want to add this 1 computer as a direct member of the """ & CollectionFirstCheckedName & """ collection?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Please Confirm Direct Membership Creation...")
			Else
				response = MsgBox("Are you sure you want to add these " & VerifiedCount & " computers as direct members of the """ & CollectionFirstCheckedName & """ collection?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Please Confirm Direct Membership Creation...")
			End If
		Else
			If MsgBoxResult.No = MsgBox("You have checked more than one collection.  Is this correct?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Multiple Collections Checked...") Then
				Exit Sub
			End If
			If VerifiedCount = 1 Then
				response = MsgBox("Are you sure you want to add this 1 computer as a direct member of the " & CollectionCheckedCount & " checked collections?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Please Confirm Direct Membership Creation...")
			Else
				response = MsgBox("Are you sure you want to add these " & VerifiedCount & " computers as direct members of the " & CollectionCheckedCount & " checked collections?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Please Confirm Direct Membership Creation...")
			End If
		End If
		
		If response = MsgBoxResult.No Then
			Exit Sub
		End If
		
		On Error GoTo AddErr
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
		
		
		Dim objResIDsToAdd As StringArr 'List of resource IDs to add to the collection
		Dim lngIndex As Integer
		
		'Take members of the list in the GUI and translate them to resource IDs
		objResIDsToAdd = New StringArr
		For lngIndex = 0 To lstComputersToAdd.Items.Count - 1
			'UPGRADE_WARNING: Couldn't resolve default property of object mobjComputerResIDs(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			objResIDsToAdd.Add(mobjComputerResIDs(VB6.GetItemString(lstComputersToAdd, lngIndex)))
		Next 
		
		If objResIDsToAdd.Count = 0 Then
			'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
			System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
			Exit Sub
		End If
		
		
		Dim objCollection As WbemScripting.SWbemObject
		Dim strCollID As Object
		
		'
		'Add the membership rules to each checked collection(s) in the GUI
		'
		
		ProgressBar1.Minimum = 0
		ProgressBar1.Maximum = TreeView1.Nodes.Count
		ProgressBar1.Value = 0
		
		Dim lngRuleIndex As Integer
		Dim objNewRules As StringArr
		Dim objRulesForSMS() As Object
		Dim objRule As WbemScripting.SWbemObject
		Dim aryExistingRules() As Object
		Dim objExistingRules As StringArr
		For lngIndex = 1 To TreeView1.Nodes.Count
			'UPGRADE_WARNING: Lower bound of collection TreeView1.Nodes has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			If TreeView1.Nodes.Item(lngIndex).Checked = True Then
				'UPGRADE_WARNING: Lower bound of collection TreeView1.Nodes has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				'UPGRADE_WARNING: Couldn't resolve default property of object strCollID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				strCollID = TreeView1.Nodes.Item(lngIndex).Name
				'UPGRADE_WARNING: Couldn't resolve default property of object strCollID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If strCollID <> "COLLROOT" Then
					'UPGRADE_WARNING: Couldn't resolve default property of object strCollID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					objCollection = mobjConn.SMSServices.Get(mobjConn.FullNamespace & ":SMS_Collection.CollectionID=""" & strCollID & """")
					
					'Get list of existing direct rules...
					objNewRules = New StringArr
					
					
					
					'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.CollectionRules. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					If IsArray(objCollection.CollectionRules) Then
						
						ProgressBar1.Minimum = 0
						'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.CollectionRules. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						If UBound(objCollection.CollectionRules) = 0 Then
							ProgressBar1.Maximum = 1
						Else
							'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.CollectionRules. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ProgressBar1.Maximum = UBound(objCollection.CollectionRules)
						End If
						ProgressBar1.Value = 0
						
						'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.CollectionRules. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						aryExistingRules = VB6.CopyArray(objCollection.CollectionRules)
						objExistingRules = New StringArr
						For lngRuleIndex = 0 To UBound(aryExistingRules)
							ProgressBar1.Value = lngRuleIndex
							'UPGRADE_WARNING: Couldn't resolve default property of object aryExistingRules(lngRuleIndex).Properties_. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If aryExistingRules(lngRuleIndex).Properties_.Count = DIRECT_RULE_PROP_COUNT Then
								'UPGRADE_WARNING: Couldn't resolve default property of object aryExistingRules().ResourceID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								objExistingRules.Add(aryExistingRules(lngRuleIndex).ResourceID)
								'UPGRADE_WARNING: Couldn't resolve default property of object aryExistingRules().ResourceID. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								Debug.Print("Existing Rule: " & CStr(aryExistingRules(lngRuleIndex).ResourceID))
							End If
						Next 
						
						'Find All ResourceIDs that aren't currently configured as direct members
						For lngRuleIndex = 0 To objResIDsToAdd.Count - 1
							If objExistingRules.IndexOf(objResIDsToAdd.Item(lngRuleIndex)) = -1 Then 'if it's not already there
								objNewRules.Add(objResIDsToAdd.Item(lngRuleIndex))
							Else
								Debug.Print("Skipping existing rule for ResourceID " & objResIDsToAdd.Item(lngRuleIndex))
							End If
						Next 
					Else
						'If there are no existing rules, we can just add all of them...
						For lngRuleIndex = 0 To objResIDsToAdd.Count - 1
							objNewRules.Add(objResIDsToAdd.Item(lngRuleIndex))
						Next 
					End If
					
					'If there are new machines to add, go ahead and add them...
					If objNewRules.Count > 0 Then
						
						ProgressBar1.Minimum = 0
						ProgressBar1.Maximum = objNewRules.Count
						ProgressBar1.Value = 0
						
						'Add all but the last one...
						If objNewRules.Count > 1 Then
							ReDim objRulesForSMS(objNewRules.Count - 2)
							For lngRuleIndex = 0 To objNewRules.Count - 2 'Add all but the last one.
								ProgressBar1.Value = lngRuleIndex
								objRule = mobjConn.SMSServices.Get("SMS_CollectionRuleDirect").SpawnInstance_
								objRule.Properties_.Item("ResourceClassName").Value = "SMS_R_System"
								objRule.Properties_.Item("ResourceID").Value = objNewRules.Item(lngRuleIndex)
								objRule.Properties_.Item("RuleName").Value = FindNameFromResID(CInt(objNewRules.Item(lngRuleIndex)))
								
								objRulesForSMS(lngRuleIndex) = objRule
							Next 
							'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.AddMembershipRules. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							objCollection.AddMembershipRules(objRulesForSMS)
						End If
						
						'Add the last one alone (this initiates a trigger to properly update the
						' collection members in the properties dialog of the SMS Admin console).
						objRule = mobjConn.SMSServices.Get("SMS_CollectionRuleDirect").SpawnInstance_
						objRule.Properties_.Item("ResourceClassName").Value = "SMS_R_System"
						objRule.Properties_.Item("ResourceID").Value = objNewRules.Item(objNewRules.Count - 1)
						objRule.Properties_.Item("RuleName").Value = FindNameFromResID(CInt(objNewRules.Item(objNewRules.Count - 1)))
						
						'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.AddMembershipRule. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						objCollection.AddMembershipRule(objRule)
						
						'UPGRADE_WARNING: Couldn't resolve default property of object objCollection.RequestRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						objCollection.RequestRefresh(True)
						
						'UPGRADE_NOTE: Object objCollection may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
						objCollection = Nothing
					End If
					
				End If
			End If
		Next 
		ProgressBar1.Value = 0
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		
		MsgBox("Direct memberships created successfully.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
		Exit Sub
		
AddErr: 
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		ProgressBar1.Value = 0
		MsgBox("Error creating direct memberships (" & Err.Number & "): " & Err.Description, MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, gstrAppTitle)
		
	End Sub
	
	Private Function FindNameFromResID(ByRef ResourceID As Integer) As String
		
		Dim lngIndex As Integer
		For lngIndex = 0 To mobjComputerResIDs.Count - 1
			'UPGRADE_WARNING: Couldn't resolve default property of object mobjComputerResIDs.Items(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If CInt(mobjComputerResIDs.Items(lngIndex)) = ResourceID Then
				'UPGRADE_WARNING: Couldn't resolve default property of object mobjComputerResIDs.Keys(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				FindNameFromResID = mobjComputerResIDs.Keys(lngIndex)
				Exit Function
			End If
        Next
        Return ""
	End Function
	
	Private Sub cmdClearList_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClearList.Click
		Dim lngIndex As Integer
		For lngIndex = lstComputersToAdd.Items.Count - 1 To 0 Step -1
			RemoveComputerFromList(lngIndex)
			System.Windows.Forms.Application.DoEvents()
		Next 
		SetGUIButtons()
	End Sub
	
	Private Sub cmdClearSelect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClearSelect.Click
		Dim lngIndex As Integer
		For lngIndex = 1 To TreeView1.Nodes.Count
			'UPGRADE_WARNING: Lower bound of collection TreeView1.Nodes has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			If TreeView1.Nodes.Item(lngIndex).Checked = True Then
				'UPGRADE_WARNING: Lower bound of collection TreeView1.Nodes has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				TreeView1.Nodes.Item(lngIndex).Checked = False
			End If
		Next 
		SetGUIButtons()
	End Sub
	
	Private Sub cmdCollProps_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCollProps.Click
		
		If TreeView1.SelectedNode Is Nothing Then
			Exit Sub
		End If
		
		Dim strCollectionID As String
		strCollectionID = TreeView1.SelectedNode.Name
		
		Dim objCollProps As frmCollProps
		objCollProps = New frmCollProps
		objCollProps.Config(mobjCollCache.NameOfCollectionID(strCollectionID), strCollectionID)
		VB6.ShowForm(objCollProps, VB6.FormShowConstants.Modal, Me)
		'UPGRADE_NOTE: Object objCollProps may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		objCollProps = Nothing
	End Sub
	
	Private Sub cmdConnect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdConnect.Click
		mobjConn = New SiteServerConnection
		mobjConn.SiteServerName = txtSiteServer.Text
		
		Dim flgSuccess As Boolean
		Dim strVersion As String
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
		flgSuccess = mobjConn.Connect((txtUserName.Text), (txtPassword.Text))
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		
		If flgSuccess Then
			'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
			System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
			strVersion = mobjConn.SMSVersion
			'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
			System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
			If strVersion = "" Then
				MsgBox("The specified account may not have the correct access permissions for site """ & mobjConn.SiteCode & """.")
				mobjConn = New SiteServerConnection
				SetGUIButtons()
				Exit Sub
			ElseIf VB.Left(strVersion, 5) <> "2.50." Then 
                MsgBox("This application only supports SMS 2003.  The site you specified is version " & strVersion & ".  Use at your own risk.")
            End If
			GetCollections()
			SaveState()
		Else
			mobjConn = New SiteServerConnection
			MsgBox("Connection failed." & vbCrLf & mobjConn.LastErrorString, MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
		End If
		
		SetGUIButtons()
		
	End Sub
	
	Private Sub LoadState()
		Dim objXML As MSXML2.DOMDocument30
		
		objXML = New MSXML2.DOMDocument30
		
		Dim flgSuccess As Boolean
		
		flgSuccess = objXML.Load(Environ("APPDATA") & "\SteveOsCollMemberWiz.xml")
		
		If flgSuccess Then
			txtSiteServer.Text = objXML.selectSingleNode("AppConfig/ServerName").Text
			txtUserName.Text = objXML.selectSingleNode("AppConfig/UserName").Text
		End If
		
	End Sub
	
	Private Sub SaveState()
		
		Dim objXML As MSXML2.DOMDocument30
		
		objXML = New MSXML2.DOMDocument30
		
		Dim objNode As MSXML2.IXMLDOMNode
		
		Dim objRootNode As MSXML2.IXMLDOMNode
		objRootNode = objXML.createNode(MSXML2.tagDOMNodeType.NODE_ELEMENT, "AppConfig", "")
		
		objNode = objXML.createNode(MSXML2.tagDOMNodeType.NODE_ELEMENT, "ServerName", "")
		objNode.Text = txtSiteServer.Text
		objRootNode.appendChild(objNode)
		
		objNode = objXML.createNode(MSXML2.tagDOMNodeType.NODE_ELEMENT, "UserName", "")
		objNode.Text = txtUserName.Text
		objRootNode.appendChild(objNode)
		
		objXML.appendChild(objRootNode)
		
		objXML.save(Environ("APPDATA") & "\SteveOsCollMemberWiz.xml")
		
	End Sub
	
	Private Sub cmdDeleteComputer_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDeleteComputer.Click
		Dim lngIndex As Integer
		For lngIndex = lstComputersToAdd.Items.Count - 1 To 0 Step -1
			If lstComputersToAdd.GetSelected(lngIndex) = True Then
				RemoveComputerFromList(lngIndex)
			End If
		Next 
		SetGUIButtons()
		
	End Sub
	
	Private Sub RemoveComputerFromList(ByRef ZeroBasedIndex As Integer)
		Dim strName As String
		
		strName = VB6.GetItemString(lstComputersToAdd, ZeroBasedIndex)
		
		If Len(txtInputComputers.Text) = 0 Then
			txtInputComputers.Text = strName
		Else
			txtInputComputers.Text = txtInputComputers.Text & vbCrLf & strName
		End If
		
		lstComputersToAdd.Items.RemoveAt(ZeroBasedIndex)
		
		System.Windows.Forms.Application.DoEvents()
		
	End Sub
	
	Private Sub cmdImport_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImport.Click
		
		DoImportText()
		
	End Sub
	
	Private Sub DoImportText()
		Dim objImport As frmImport
		objImport = New frmImport
		VB6.ShowForm(objImport, VB6.FormShowConstants.Modal, Me)
		'UPGRADE_NOTE: Object objImport may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		objImport = Nothing
	End Sub
	
	Private Sub cmdNewColl_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNewColl.Click
		Dim strCollectionName As String
		Dim strParentCollectionID As String
		Dim strParentCollectionName As String
		
		strParentCollectionID = TreeView1.SelectedNode.Name
		strParentCollectionName = mobjCollCache.NameOfCollectionID(strParentCollectionID)
		
		Dim response As MsgBoxResult
		
		response = MsgBox("Would you like to create a new child of collection """ & strParentCollectionName & """ (" & strParentCollectionID & ")?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, gstrAppTitle)
		If response = MsgBoxResult.No Then
			Exit Sub
		End If
		
		strCollectionName = InputBox("Please specify the name of the new collection to be created under """ & strParentCollectionName & """:", "Create new Child Collection", "")
		
		If strCollectionName = "" Then
			Exit Sub
		End If
		
		Debug.Print("Creating child collection '" & strCollectionName & "' under '" & strParentCollectionID & "'.")
		
		Dim objWalkback As StringArr
		objWalkback = WalkbackList(strParentCollectionID)
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
		
		Dim objColl As SMSCollection
		Dim flgSuccess As Boolean
		objColl = New SMSCollection
		
		objColl.Name = strCollectionName
		objColl.ParentID = strParentCollectionID
		flgSuccess = objColl.Create(mobjConn.SMSServices)
		
		CacheCollNames()
		
		GetCollections()
		
		
		Dim lngIndex As Integer
		Dim tempNode As System.Windows.Forms.TreeNode
		
		For lngIndex = objWalkback.Count - 1 To 0 Step -1
			Debug.Print("...expanding " & objWalkback.Item(lngIndex))
            tempNode = GetNodeByName(objWalkback.Item(lngIndex))
			TreeView1_AfterExpand(TreeView1, New System.Windows.Forms.TreeViewEventArgs(tempNode))
		Next 
		
        GetNodeByName(strParentCollectionID).EnsureVisible()
        GetNodeByName(strParentCollectionID).Expand()
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		
		SetGUIButtons()
		
	End Sub
	
	Function WalkbackList(ByVal CollectionID As String) As StringArr
		
		WalkbackList = New StringArr
		
        WalkbackList.Add(CollectionID)

        Dim strParentName As String = GetParentNodeName(CollectionID)
        While strParentName <> "" And strParentName <> "COLLROOT"
            WalkbackList.Add(strParentName)
            strParentName = GetParentNodeName(strParentName)
        End While


    End Function

    Private Function GetNodeByName(ByVal TheNodeName As String) As TreeNode
        If TreeView1.Nodes.Find(TheNodeName, True).Length = 0 Then
            Return Nothing
        Else
            Return TreeView1.Nodes.Find(TheNodeName, True)(0)
        End If
    End Function

    Private Function GetParentNodeName(ByVal TheNodeName As String) As String
        If GetNodeByName(TheNodeName) Is Nothing Then
            Return ""
        Else
            Dim objNode As TreeNode = GetNodeByName(TheNodeName)
            objNode = TreeView1.Nodes.Find(TheNodeName, True)(0)
            If objNode.Parent Is Nothing Then
                Return ""
            Else
                Return objNode.Parent.Name
            End If
        End If
    End Function
	
	
	
	Private Sub cmdParse_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdParse.Click
		
		Dim objList As StringArr
		objList = New StringArr
		
		Dim strComputerList As String
		
		strComputerList = txtInputComputers.Text
		
		Dim lngResponse As Integer
		If InStr(1, strComputerList, "%", CompareMethod.Binary) > 0 Then
			lngResponse = MsgBox("The % character can't be used in any computer names.  Do you want to automatically strip any % symbols from the computer list?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrAppTitle)
			If lngResponse = MsgBoxResult.No Then
				MsgBox("Please remove the % symbols from the list.  Aborting.", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, gstrAppTitle)
				SetGUIButtons()
				Exit Sub
			End If
		End If
		
		strComputerList = MyReplace(strComputerList, Chr(9), "")
		strComputerList = MyReplace(strComputerList, Chr(0), "")
		
		If chkParse(0).CheckState = System.Windows.Forms.CheckState.Checked Then
			strComputerList = MyReplace(strComputerList, ",", "%")
		End If
		If chkParse(1).CheckState = System.Windows.Forms.CheckState.Checked Then
			strComputerList = MyReplace(strComputerList, vbCrLf, "%")
			strComputerList = MyReplace(strComputerList, Chr(13), "%")
			strComputerList = MyReplace(strComputerList, Chr(10), "%")
		Else
			strComputerList = MyReplace(strComputerList, vbCrLf, "")
			strComputerList = MyReplace(strComputerList, Chr(13), "")
			strComputerList = MyReplace(strComputerList, Chr(10), "")
		End If
		If chkParse(2).CheckState = System.Windows.Forms.CheckState.Checked Then
			strComputerList = MyReplace(strComputerList, ";", "%")
		End If
		If chkParse(3).CheckState = System.Windows.Forms.CheckState.Checked Then
			strComputerList = MyReplace(strComputerList, " ", "%")
		End If
		
		If chkStripQuotes.CheckState = System.Windows.Forms.CheckState.Checked Then
			objList.GenerateNewFromString(strComputerList, "%", True, False, """")
		Else
			objList.GenerateNewFromString(strComputerList, "%", True, False)
		End If
		
		Dim lngIndex As Integer
		
		For lngIndex = 0 To objList.Count - 1
			lstComputersToAdd.Items.Add(objList.Item(lngIndex))
		Next 
		
		txtInputComputers.Text = ""
		
		SetGUIButtons()
		
		lstComputersToAdd.Font = VB6.FontChangeBold(lstComputersToAdd.Font, False)
		lstComputersToAdd.Font = VB6.FontChangeUnderline(lstComputersToAdd.Font, False)
		
	End Sub
	
	Private Sub cmdRefreshCollections_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRefreshCollections.Click
		If mobjConn.Connected = False Then
			MsgBox("You must connect to the site server before refreshing the collection list.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
			Exit Sub
		End If
		
		CacheCollNames()
		GetCollections()
		
	End Sub
	
	Private Sub GetCollections()
		
		If mobjConn.Connected = False Then
			Exit Sub
		End If
		
		On Error GoTo GetCollectionsErr
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
		
		If mobjCollCache Is Nothing Then
			CacheCollNames()
		End If
		
		If mobjCollCache.Count = 0 Then
			MsgBox("Unable to cache Collection names.  Are you sure you have sufficient access to this server via WBEM?", MsgBoxStyle.Exclamation, gstrAppTitle)
			Exit Sub
		End If
		
		Dim objList As WbemScripting.SWbemObjectSet
		Dim objItem As WbemScripting.SWbemObject
		
		objList = mobjConn.SMSServices.ExecQuery("Select subCollectionID from SMS_CollectToSubCollect where parentCollectionID = ""COLLROOT""",  , WbemScripting.WbemFlagEnum.wbemFlagForwardOnly + WbemScripting.WbemFlagEnum.wbemFlagReturnImmediately)
		
		Dim objCollList As SMSCollectionList
		objCollList = New SMSCollectionList
		
		For	Each objItem In objList
			With objItem
				objCollList.AddCollection((.Properties_.Item("subCollectionID").Value), mobjCollCache.NameOfCollectionID((.Properties_.Item("subCollectionID").Value)), mobjCollCache.OwnedByCollectionID((.Properties_.Item("subCollectionID").Value)))
			End With
		Next objItem
		
		Dim lngIndex As Integer
		Dim objRoot As System.Windows.Forms.TreeNode
		Dim objNode, objChild As System.Windows.Forms.TreeNode
		
		TreeView1.Nodes.Clear()
		
		objRoot = TreeView1.Nodes.Add("")
		objRoot.Text = "Collections on " & mobjConn.SiteServerName & " (" & mobjConn.SiteCode & ")"
		objRoot.Name = "COLLROOT"
		objRoot.ImageKey = "SMSSite"
		'UPGRADE_ISSUE: MSComctlLib.Node property objRoot.Sorted was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
        'objRoot.Sorted = True
		objRoot.Expand()
		
		For lngIndex = 0 To objCollList.Count - 1
			'UPGRADE_WARNING: Add method behavior has changed Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DBD08912-7C17-401D-9BE9-BA85E7772B99"'
			objNode = TreeView1.Nodes.Find("COLLROOT", True)(0).Nodes.Add("") 'Add it as a child to COLLROOT
			objNode.Text = mobjCollCache.NameOfCollectionID((objCollList.Item(lngIndex).ID))
			objNode.Name = objCollList.Item(lngIndex).ID
			If objCollList.Item(lngIndex).OwnedByThisSite = True Then
				objNode.ImageKey = "Collection"
			Else
				objNode.ImageKey = "CollLock"
			End If
			'UPGRADE_ISSUE: MSComctlLib.Node property objNode.Sorted was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
            'objNode.Sorted = True
			objNode.Collapse()
			
			'create a bogus child so that we get the + sign...
            objChild = TreeView1.Nodes.Find(objCollList.Item(lngIndex).ID, True)(0).Nodes.Add("")
            objChild.Name = "!" & objCollList.Item(lngIndex).ID
            objChild.ImageKey = objNode.ImageKey

			objChild.Text = mstrLoading
		Next 
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		
		Exit Sub
		
GetCollectionsErr: 
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		Debug.Print("Error Loading Collection List (" & Err.Number & "): " & Err.Description)
		
	End Sub
	
	
	
	Public Sub mnuFileComputerMode_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuFileComputerMode.Click
		HandleModes("Computer")
	End Sub
	
	Private Sub HandleModes(ByRef NewMode As String)
		
		If NewMode = "Computer" Then
			mnuFileComputerMode.Checked = True
			mnuFileUserMode.Checked = False
		Else
			mnuFileComputerMode.Checked = False
			mnuFileUserMode.Checked = True
		End If
		
	End Sub
	
	Public Sub mnuFileExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuFileExit.Click
		Me.Close()
	End Sub
	
	Public Sub mnuFileImportText_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuFileImportText.Click
		DoImportText()
	End Sub
	
	Public Sub mnuFileUserMode_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuFileUserMode.Click
		HandleModes("User")
	End Sub
	
	Public Sub mnuHelpAbout_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuHelpAbout.Click
		Dim objHelp As frmHelpAbout
		objHelp = New frmHelpAbout
		VB6.ShowForm(objHelp, VB6.FormShowConstants.Modal, Me)
		'UPGRADE_NOTE: Object objHelp may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		objHelp = Nothing
	End Sub
	
	Private Sub optObjectMode_Click(ByRef Index As Short)
		
		If lstComputersToAdd.Items.Count > 0 Then
			
		End If
	End Sub
	
	Private Sub TreeView1_AfterExpand(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterExpand
		Dim Node As System.Windows.Forms.TreeNode = eventArgs.Node
		
		Dim objNode As System.Windows.Forms.TreeNode
		
		On Error GoTo TreeViewExpandErr
		
		Node.ImageKey = "Hourglass"
		
		Dim objCollList As SMSCollectionList
		Dim lngIndex As Integer
		Dim objChild As System.Windows.Forms.TreeNode
		Dim strName As String
		Dim objList As WbemScripting.SWbemObjectSet
		Dim objItem As WbemScripting.SWbemObject
		If Node.GetNodeCount(False) = 1 Then
			objNode = Node.FirstNode
			If objNode.Text = mstrLoading Then
				Debug.Print("Loading child colls for '" & Node.Name & "' now...")
				'UPGRADE_WARNING: MSComctlLib.Nodes method TreeView1.Nodes.Remove has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
                TreeView1.Nodes.Remove(objNode)
				
				
				'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
				System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
				objList = Me.mobjConn.SMSServices.ExecQuery("Select subCollectionID from SMS_CollectToSubCollect where parentCollectionID = """ & Node.Name & """",  , WbemScripting.WbemFlagEnum.wbemFlagForwardOnly + WbemScripting.WbemFlagEnum.wbemFlagReturnImmediately)
				
				objCollList = New SMSCollectionList
				
				For	Each objItem In objList
					objCollList.AddCollection((objItem.Properties_.Item("subCollectionID").Value), objCollList.NameOfCollectionID((objItem.Properties_.Item("subCollectionID").Value)), objCollList.OwnedByCollectionID((objItem.Properties_.Item("subCollectionID").Value)))
				Next objItem
				
				
				For lngIndex = 0 To objCollList.Count - 1
					objNode = TreeView1.Nodes.Find(Node.Name, True)(0).Nodes.Add("") 'Add it as a child to the node...
					
					strName = mobjCollCache.NameOfCollectionID((objCollList.Item(lngIndex).ID))
					If Len(strName) = 0 Then
						CacheCollNames()
					End If
					strName = mobjCollCache.NameOfCollectionID((objCollList.Item(lngIndex).ID))
					If Len(strName) = 0 Then
						strName = "Collection ID " & objCollList.Item(lngIndex).ID
					End If
					
					objNode.Text = mobjCollCache.NameOfCollectionID((objCollList.Item(lngIndex).ID))
					
					
					objNode.Name = objCollList.Item(lngIndex).ID
					objNode.Collapse()
					'UPGRADE_ISSUE: MSComctlLib.Node property objNode.Sorted was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
                    'objNode.Sorted = True
					objNode.ImageKey = "Collection"
					objNode.ImageKey = mobjCollCache.IconForCollectionID((objCollList.Item(lngIndex).ID))
					
					'UPGRADE_ISSUE: MSComctlLib.Node property objNode.Sorted was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
                    'objNode.Sorted = True
					
					'UPGRADE_WARNING: Add method behavior has changed Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DBD08912-7C17-401D-9BE9-BA85E7772B99"'
					objChild = TreeView1.Nodes.Find(objCollList.Item(lngIndex).ID, True)(0).Nodes.Add("")
					objChild.Name = "!" & objCollList.Item(lngIndex).ID
					objChild.ImageKey = "Collection" 'this is a bogus entry to get the +
					'UPGRADE_ISSUE: MSComctlLib.Node property objChild.Sorted was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
                    'objChild.Sorted = True
					objChild.Text = mstrLoading
				Next 
				
				'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
				System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
				
			End If
		End If
		Node.ImageKey = mobjCollCache.IconForCollectionID((Node.Name))
		Exit Sub
		
TreeViewExpandErr: 
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		Debug.Print("Error expanding view...")
		Node.ImageKey = "Collection"
		
	End Sub
	
	
	
	
	
	Private Sub cmdVerifyNames_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdVerifyNames.Click
		
		Dim objComputerList As StringArr
		Dim lngIndex As Integer
		objComputerList = New StringArr
		
		For lngIndex = 0 To lstComputersToAdd.Items.Count - 1
			objComputerList.Add(VB6.GetItemString(lstComputersToAdd, lngIndex))
		Next 
		
		Dim lngAfterCount, lngBeforeCount, lngDupCount As Integer
		lngBeforeCount = objComputerList.Count
		objComputerList.EliminateDuplicates()
		lngAfterCount = objComputerList.Count
		lngDupCount = lngBeforeCount - lngAfterCount
		
		If lngDupCount > 0 Then
			'fix the listbox to remove the duplicates...
			lstComputersToAdd.Items.Clear()
			System.Windows.Forms.Application.DoEvents()
			For lngIndex = 0 To objComputerList.Count - 1
				lstComputersToAdd.Items.Add(objComputerList.Item(lngIndex))
			Next 
		End If
		
		StatusBar1.Text = ""
		
		If mobjConn.Connected = False Then
			MsgBox("You must connect to the site server before verifying these names.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
			SetGUIButtons()
			Exit Sub
		End If
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
		
		Dim objValidList, objRemovedList As StringArr
		objValidList = New StringArr
		objRemovedList = New StringArr
		
		Const StepValue As Integer = 15
		
		Dim strName As String
		Dim lngCheckIndex As Integer
		Dim objList As WbemScripting.SWbemObjectSet
		Dim objItem As WbemScripting.SWbemObject
		For lngIndex = 0 To objComputerList.Count - 1 Step StepValue
			
			
			If lngIndex + StepValue < objComputerList.Count Then
				StatusBar1.Text = "Verifying items " & CStr(lngIndex + 1) & " to " & CStr(lngIndex + StepValue) & "..."
			Else
				StatusBar1.Text = "Verifying items " & CStr(lngIndex + 1) & " to " & objComputerList.Count & "..."
			End If
			
			
            objList = mobjConn.SMSServices.ExecQuery("Select Name, ResourceID from SMS_R_System where Name in (" & objComputerList.Glue(GlueChars:=",", QuoteChars:="'", StartIndex:=lngIndex, MaxCount:=StepValue) & ")", , WbemScripting.WbemFlagEnum.wbemFlagForwardOnly + WbemScripting.WbemFlagEnum.wbemFlagReturnImmediately)
			'Cache Resource ID in dictionary...
			For	Each objItem In objList
				
				strName = objItem.Properties_.Item("Name").Value
				
				If Not mobjComputerResIDs.Exists(strName) Then
					mobjComputerResIDs.Add(strName, objItem.Properties_.Item("ResourceID").Value)
				End If
				
				If Not objValidList.Exists(strName) Then
					objValidList.Add(strName)
					Debug.Print(strName & " is valid.")
				Else
					Debug.Print(strName & " is dup'd.")
				End If
			Next objItem
			
			
			'Check to see if each computer is valid
			For lngCheckIndex = lngIndex To (lngIndex + StepValue - 1)
				If lngCheckIndex < objComputerList.Count Then
					If objValidList.IndexOf(objComputerList.Item(lngCheckIndex)) = -1 Then
						'this one is not valid so add it to the removed list...
						objRemovedList.Add(objComputerList.Item(lngCheckIndex))
					End If
				End If
			Next 
			
		Next lngIndex
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		
        txtInputComputers.Text = objRemovedList.Glue(GlueChars:=vbCrLf)
		lstComputersToAdd.Items.Clear()
		For lngIndex = 0 To objValidList.Count - 1
			lstComputersToAdd.Items.Add(objValidList.Item(lngIndex))
		Next 
		
		MsgBox("Verification complete." & vbCrLf & vbCrLf & lstComputersToAdd.Items.Count & " computer name(s) accepted." & vbCrLf & vbCrLf & objRemovedList.Count & " computer name(s) rejected and moved back into the left-hand pane." & vbCrLf & vbCrLf & lngDupCount & " duplicate computer name(s) removed.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
		lstComputersToAdd.Font = VB6.FontChangeBold(lstComputersToAdd.Font, True)
		lstComputersToAdd.Font = VB6.FontChangeUnderline(lstComputersToAdd.Font, True)
		
		SetGUIButtons()
		
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Function CollectionCheckedCount() As Integer
		Dim lngCount, lngIndex As Integer
		
        For lngIndex = 0 To TreeView1.Nodes.Count - 1
            If TreeView1.Nodes.Item(lngIndex).Checked = True Then
                lngCount = lngCount + 1
            End If
        Next
		CollectionCheckedCount = lngCount
	End Function
	
    Private Function CollectionSelectedName() As String
        If TreeView1.SelectedNode Is Nothing Then
            Return ""
        Else
            Return TreeView1.SelectedNode.Name
        End If
        'Dim lngIndex As Integer
        'CollectionSelectedName = ""
        'TreeView1.SelectedNode.Text
        'For lngIndex = 0 To TreeView1.Nodes.Count - 1
        '    If TreeView1.Nodes.Item(lngIndex).IsSelected = True Then
        '        CollectionSelectedName = TreeView1.Nodes.Item(lngIndex).Text
        '    End If
        'Next
    End Function
	
	Private Function CollectionSelectedID() As String
		Dim lngIndex As Integer
		CollectionSelectedID = ""
        For lngIndex = 0 To TreeView1.Nodes.Count - 1
            If TreeView1.Nodes.Item(lngIndex).IsSelected = True Then
                CollectionSelectedID = TreeView1.Nodes.Item(lngIndex).Name
            End If
        Next
	End Function
	
	
	Private Sub SetGUIButtons()
		
		If lstComputersToAdd.Font.Bold = True And lstComputersToAdd.Items.Count > 0 And CollectionCheckedCount > 0 Then
			
			cmdAdd.Enabled = True
		Else
			cmdAdd.Enabled = False
		End If
		
		cmdClearList.Enabled = (lstComputersToAdd.Items.Count > 0)
		cmdVerifyNames.Enabled = (cmdClearList.Enabled) 'same...
		
		cmdDeleteComputer.Enabled = (lstComputersToAdd.SelectedItems.Count > 0)
		cmdClearSelect.Enabled = (CollectionCheckedCount > 0)
		cmdRefreshCollections.Enabled = (TreeView1.Nodes.Count > 1)
		cmdParse.Enabled = (Len(txtInputComputers.Text) > 0)
		cmdNewColl.Enabled = (Len(CollectionSelectedName) > 0)
		cmdCollProps.Enabled = (Not (TreeView1.SelectedNode Is Nothing))
		
		
		cmdConnect.Enabled = Not (Len(txtUserName.Text) > 0 And Len(txtPassword.Text) = 0)
		
		CheckConnectStatus()
		
		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		
	End Sub
	
	Private Sub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Me.Text = gstrAppTitle & " " & My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Revision
		mobjConn = New SiteServerConnection
		mobjComputerResIDs = New Scripting.Dictionary
		LoadState()
	End Sub
	
	
	Private Sub lstCollections_Click()
		SetGUIButtons()
	End Sub
	
	'UPGRADE_WARNING: Event lstComputersToAdd.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub lstComputersToAdd_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lstComputersToAdd.SelectedIndexChanged
		SetGUIButtons()
	End Sub
	
	Private Sub mobjConn_NewConnectionStatus(ByRef Connected As Boolean) Handles mobjConn.NewConnectionStatus
		CheckConnectStatus()
	End Sub
	
	Private Sub CheckConnectStatus()
		If mobjConn.Connected Then
			StatusBar1.Text = "Connected to site " & mobjConn.SiteCode & "."
		Else
			StatusBar1.Text = "Not Connected."
			lstComputersToAdd.Font = VB6.FontChangeBold(lstComputersToAdd.Font, False)
			lstComputersToAdd.Font = VB6.FontChangeUnderline(lstComputersToAdd.Font, False)
		End If
	End Sub
	
	Private Sub TreeView1_AfterCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
		Dim Node As System.Windows.Forms.TreeNode = eventArgs.Node
		If Node.Name = "COLLROOT" Then
			tmrCollRoot.Enabled = True 'Can't select the root node!!!
			MsgBox("Creating Direct Memberships in the Collection Root is not supported.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
			'UPGRADE_WARNING: MSComctlLib.Node property Node.Image has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		ElseIf Node.ImageKey = "CollLock" Then 
			tmrCollRoot.Enabled = True 'Can't select the root node!!!
			MsgBox("Creating Direct Memberships is only supported in collections owned by this site.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, gstrAppTitle)
		End If
		
		SetGUIButtons()
	End Sub
	
	Private Sub tmrCollRoot_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrCollRoot.Tick
		tmrCollRoot.Enabled = False
		TreeView1.Nodes.Item("COLLROOT").Checked = False
		Dim lngIndex As Integer
        For lngIndex = 0 To TreeView1.Nodes.Count - 1
            If TreeView1.Nodes.Item(lngIndex).Checked = True Then
                'UPGRADE_WARNING: MSComctlLib.Node property TreeView1.Nodes.Item.Image has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
                If TreeView1.Nodes.Item(lngIndex).ImageKey = "CollLock" Then
                    TreeView1.Nodes.Item(lngIndex).Checked = False
                End If
            End If
        Next
	End Sub
	
	Private Sub TreeView1_NodeClick(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
        SetGUIButtons()
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        SetGUIButtons()
    End Sub
	
	'UPGRADE_WARNING: Event txtInputComputers.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub txtInputComputers_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtInputComputers.TextChanged
		SetGUIButtons()
	End Sub
	
	'UPGRADE_WARNING: Event txtPassword.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub txtPassword_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtPassword.TextChanged
		SetGUIButtons()
	End Sub
	
	'UPGRADE_WARNING: Event txtSiteServer.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub txtSiteServer_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtSiteServer.TextChanged
		
		If mobjConn.Connected = True Then
			mobjConn = New SiteServerConnection
			mobjConn_NewConnectionStatus((mobjConn.Connected))
			TreeView1.Nodes.Clear()
            mobjCollCache = Nothing
			SetGUIButtons()
		End If
		
	End Sub
	
	'UPGRADE_WARNING: Event txtUserName.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub txtUserName_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtUserName.TextChanged
		SetGUIButtons()
	End Sub

    
End Class